"""
============================
 _*_coding : UTF-8 _*_
 Team ： Administrator
 Personnel ： Ms Yang Xiao
 Data ： 2020/3/24  20:14
 File ： 梨视频.py
 Developer Kits ： PyCharm
============================
"""
import requests
import re
url_1 = 'https://www.pearvideo.com/category_8'
url_s = 'https://www.pearvideo.com/'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
response = requests.get(url_1, headers=headers)
# print(response.text)
re_txt = re.findall("""<a href="(.*?)" class="vervideo-lilink actplay">""",response.text)
# print(re_txt)
for url_2 in re_txt:
    url = url_s + url_2
    res = requests.get(url,headers=headers)
    # print(res.text)
    video_url = re.findall('srcUrl="(.*?)"',res.text)[0]
    video_name = re.findall(' <img class="img" src=".*?" alt="(.*?)">',res.text)[0]
    # print(video_url,video_name)
    print('正在下载{}'.format(video_name))
    vide = requests.get(video_url,headers=headers).content
    with open('梨视频/' + video_name + '.mp4', 'wb')as f:
        f.write(vide)
    print('下载完毕{}'.format(video_name))





















